package artid.com.arttogo.view.horizonlistview;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import artid.com.arttogo.R;
import artid.com.arttogo.activity.CollectionDetailPagerActivity;
import artid.com.arttogo.utils.MyBitmapImageViewTarget;
import artid.com.arttogo.utils.NetUtils;

/**
 * 
*    
* 项目名称：ArtworkArt   
* 类名称：NewartistArtistHorizontalList_Adapter   
* 类描述：艺术家列表适配器（横向的ListView）      
* 创建人：耿卫斌   
* 创建时间：2017-1-4 下午4:13:15   
*
 */
public class NewartistArtistHorizontalList_Adapter extends BaseAdapter {
	private Context mContext;
	private List<NewartistArtistListParser.NewartistArtistList_ArtistList.NewartistArtistList_ArtInfo> list;
	ArrayList<String> listIds;
	public NewartistArtistHorizontalList_Adapter(Context mContext,
			List<NewartistArtistListParser.NewartistArtistList_ArtistList.NewartistArtistList_ArtInfo> list) {
		super();
		this.mContext = mContext;
		this.list = list;
		listIds = new ArrayList<String>();
		for (int i = 0; i < list.size(); i++) {
			String idString = list.get(i).getArt_id();
			listIds.add(idString);
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_newartistartisthorizontallist, null);
			holder.img=(ImageView) v.findViewById(R.id.item_newartistartisthorizontallist_img);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		Glide.with(mContext).load(list.get(position).getArtUrl()
				+ "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /3) + "x10.png"
				).asBitmap().centerCrop()
		.placeholder(R.drawable.ic_menu_rotate).error(R.drawable.ic_menu_rotate)
		.into(new MyBitmapImageViewTarget(holder.img));
		holder.img.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
				
				Intent intent = new Intent(mContext,CollectionDetailPagerActivity.class);
				intent.putStringArrayListExtra("id", listIds);
				intent.putExtra("index", position);
				intent.putExtra("titleName", list.get(position).getArtName());
				mContext.startActivity(intent);
					
			}
		});
		return v;
	}
	class ViewHolder {
		ImageView img;
	}
}
